Attribute VB_Name = "modServerInit"
Option Explicit

Public Sub InitServer()
    frmLoadServer.Show
    frmLoadServer.Refresh
    Call SetStatus("Setting Global Vars")
    
    'Set Global Variables
    SEP_CHAR = Chr$(0)
    MAX_PLAYERS = 10 'Change IT to read
    SAVE_INTERVAL = 3 'Change IT to read
    
    frmServer.tmrSave.Interval = SAVE_INTERVAL * 1000
    ReDim Player(1 To MAX_PLAYERS) As PlayerC
    Call IncBar
    
    SetStatus ("Checking Files")
    'Making Folders
    If Not FolderExists(App.Path & "\Users") Then
        Call MkDir(App.Path & "\Users")
    End If
    If Not FolderExists(App.Path & "\News") Then
        Call MkDir(App.Path & "\News")
        Call WriteINI("NEWS", "NEWS", "Enter Your News Here!", App.Path & "\News\News.ini")
        Call WriteINI("NEWS", "TITLE", "Enter News Title Here!", App.Path & "\News\News.ini")
    End If
    
    If Not FolderExists(App.Path & "\PlayerInvs") Then _
        Call MkDir(App.Path & "\PlayerInvs")
        
    If Not FolderExists(App.Path & "\PlayerSpells") Then _
        Call MkDir(App.Path & "\PlayerSpells")
    Call IncBar
    'Load Server Networking
    Call SetStatus("Starting To Listen")
    frmServer.Socket(0).LocalPort = "41555"
    Dim sServerMsg As String
    sServerMsg = "Server listening on port: " & frmServer.Socket(0).LocalPort
    AddLog (sServerMsg)
    frmServer.Socket(0).Listen
    If frmServer.Socket(0).State <> sckListening Then
        sServerMsg = "Server not listening on specified port!"
        frmServer.listServerLog.AddItem (sServerMsg)
    End If
    Call IncBar
    
    
    Call SetStatus("Listing Users")
    Call ListReggedPasswords
    Call ListReggedUsernames
    Call IncBar

    Call Unload(frmLoadServer)
    frmServer.Visible = True
End Sub

Public Sub SetStatus(status As String)
    frmLoadServer.lblStatus = status
    frmLoadServer.lblStatus.Refresh
End Sub

Private Sub IncBar()
    frmLoadServer.barLoad.Value = frmLoadServer.barLoad.Value + 1
End Sub
